package com.hopu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopu.mapper.StaffRoleMapper;
import com.hopu.pojo.StaffRole;
import com.hopu.service.StaffRoleService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author YwaiX
 * @since 2024-09-12
 */
@Service
public class StaffRoleServiceImpl extends ServiceImpl<StaffRoleMapper, StaffRole> implements StaffRoleService {
    @Resource
    private StaffRoleMapper staffRoleMapper;

    @Override
    public void updateRoleName(Integer roleId, List<Integer> roleNameList) {
        baseMapper.deleteById(roleId);

        List<StaffRole> roles = roleNameList.stream().map(roleNameId -> {
            StaffRole staffRole = new StaffRole();
            staffRole.setStaffId(roleId);
            staffRole.setRoleId(roleNameId);
            return staffRole;
        }).collect(Collectors.toList());

        saveBatch(roles);
    }

    @Override
    public List<StaffRole> getRoleById(Integer staffId) {
        return staffRoleMapper.getRoleById(staffId);
    }
}
